package com.pubinfo.passbook.common.enums;

import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * 地区
 */
@Getter
@Slf4j
public enum OrgIdEnum {

    PROVINCE(3300, 1, "省本部"),
    HANG_ZHOU(3301, 2, "杭州"),
    NING_BO(3302, 3, "宁波"),
    WEN_ZHOU(3303, 4, "温州"),
    JIA_XING(3304, 5, "嘉兴"),
    HU_ZHOU(3305, 6, "湖州"),
    SHAO_XING(3306, 32518, "绍兴"),
    JIN_HUA(3307, 7, "金华"),
    QU_ZHOU(3308, 12, "衢州"),
    LI_SHUI(3309, 10, "丽水"),
    TAI_ZHOU(3310, 8, "台州"),
    ZHOU_SHAN(3311, 11, "舟山"),
    CHUAN_SHU_JU(3312, 10000028, "传输局"),
    ;

    private Integer cityCode;

    private Integer orgId;

    private String desc;

    OrgIdEnum(Integer cityCode, Integer orgId, String desc) {
        this.cityCode = cityCode;
        this.orgId = orgId;
        this.desc = desc;
    }

    public static Integer getEnum(String cityCode) {
      try {
        Integer cCode = Integer.parseInt(cityCode.substring(1));
    
        for (OrgIdEnum orgIdEnum : OrgIdEnum.values()) {
          if (cCode.intValue() == orgIdEnum.getCityCode().intValue()) {
            return orgIdEnum.getOrgId();
          }
        }
      } catch (Exception e) {
        log.error("获取对应地区ID失败：{}", e.getMessage());
        }
        return 0;
    }

    public static List<OrgIdData> getEnumList() {
        List<OrgIdData> list = new ArrayList<>();
        for (OrgIdEnum orgIdEnum : OrgIdEnum.values()) {
            list.add(new OrgIdData() {{
                setOrgId(orgIdEnum.getOrgId());
                setCityCode(orgIdEnum.getCityCode());
                setDesc(orgIdEnum.getDesc());
            }});
        }
        return list;
    }

    @Data
    static class OrgIdData {
        private Integer cityCode;

        private Integer orgId;

        private String desc;
    }

}
